﻿Public Class Form1
    Dim WithEvents server As DCM_HPServer.DCM_HPServer
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Start()
    End Sub
    Private Sub Start()
        If IsNothing(server) Then
            server = New DCM_HPServer.DCM_HPServer()
            server.a_Start()
        Else
            If server.HPServer.IsStarted = False Then
                server.a_Start()
            Else
                Throw New Exception("已经启动,无法重复启动")
            End If
        End If
    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Try
            Start()
        Catch ex As Exception
            showstr(ex.Message)
        End Try

    End Sub

    Private Sub server_Out_ShowString(ShowString As String) Handles server.Out_ShowString
        showstr(ShowString)
    End Sub
    Private Sub showstr(str As String)
        If LB.InvokeRequired Then
            LB.Invoke(New D_showstr(AddressOf showstr), str)
        Else
            LB.Items.Add(str)
            LB.SelectedIndex = LB.Items.Count - 1
        End If
    End Sub
    Private Delegate Sub D_showstr(str As String)

    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Try
            server.a_Stop()
        Catch ex As Exception
            showstr(ex.Message)
        End Try
    End Sub

    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        LB.Items.Clear()
    End Sub
End Class
